package org.mspring.platform.web.render;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Gao Youbo
 * @since May 12, 2012
 */
public class RSSRender extends AbstractResponseRender {

    private static final Logger log = LoggerFactory.getLogger(RSSRender.class);

    private String content;

    public void setContent(String content) {
        this.content = content;
    }

    public RSSRender(String content) {
        this.content = content;
    }

    @Override
    public void render(HttpServletResponse response) {
        try {
            response.setContentType("application/rss+xml");
            response.setCharacterEncoding("UTF-8");

            try (PrintWriter writer = response.getWriter()) {
                writer.write(this.content);
            }
        } catch (IOException e) {
            log.warn("RSS Render failed");
        }
    }

}
